Long Double EMA and Close
ストラテジーを作成
https://gyazo.com/76bce99c64690c89efe1de22a67cdf34
使用感
大きなトレンドをしっかり獲れている感じがする
ダメな銘柄でも損失は小さく抑えられているはず
その確認をしたい
バックテスト
期間
2005年1月1日 ~ 2017年12月31日
12年間
銘柄
為替(5):
USDJPY、EURJPY、GBPJPY、CHFJPY、CADJPY
株価指数(5):
NKY 日経225、DJI NYダウ、DAX ドイツ、UKX イギリス、HSI 香港ハンセン
日本株(5):
6098リクルート、4452花王、5711三菱マテリアル、7201日産、9984ソフトバンクグループ
米株(5):
AAPLアップル、AXPアメリカン・エクスプレス、BAボーイング、JNJジョンソン・エンド・ジョンソン、MCDマクドナルド
海外商品(5):
金、白金、原油、コーン、大豆
その他
資金管理:単利
各主要な市場から5銘柄ずつピックアップしてテスト。
テスト1
table:テスト1設定
s m l Pyramiding
1 300 600 5-ATR300 上限4
table:テスト1結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 79.32 43.95 87 19 21.84 6.358 318 31
EURJPY 57.44 40.20 108 27 25.00 4.146 205 26
GBPJPY 515.71 21.55 58 19 32.76 15.746 478 16
CHFJPY 16.34 76.30 114 22 19.30 4.673 228 22
CADJPY -46.22 86.49 123 23 18.70 3.168 207 34
NKY 19431.49 8967.63 100 30 30.00 4.063 186 26
DJI 22862.77 8969.65 95 21 22.11 7.606 322 21
DAX 10399.40 5618.07 84 26 30.95 3.881 268 27
UKX -4804.70 7166.90 88 21 23.86 1.797 185 35
HSI 1791.21 44529.80 93 25 26.88 2.806 200 37
6098 2003.50 0 4 4 100.00 - 328 -
4452 -2590.00 8363.00 102 31 30.39 1.647 112 32
5711 -5035.00 12455.00 109 26 23.85 2.272 137 33
7201 -4068.60 4145.60 122 20 16.39 0.592 83 31
9984 10841.00 7341.00 75 20 26.67 5.061 235 37
AAPL 511.81 53.66 61 23 37.70 9.434 416 24
AXP 80.96 33.88 78 23 29.49 4.102 220 35
BA 760.58 114.79 91 27 29.67 9.669 269 28
JNJ 97.14 123.42 109 21 19.27 1.501 100 34
MCD 147.97 47.85 114 35 30.70 5.162 174 22
GOLD 266230.00 73310.00 60 16 26.67 8.027 423 46
PLATINUM 53900.00 96195.00 82 23 28.05 3.437 255 25
WTI 99170.00 165880.00 124 21 16.94 6.816 250 22
CORN 2737.50 28437.50 114 23 20.18 4.090 189 28
SOY BEANS 33850.00 53887.50 115 21 18.26 5.507 222 23
TOTAL 2310 567 24.55 4.878
破産の確率 0.00
期待値/リスク 0.443
収益の見込み 1023.104
※ 破産の確率は損失の許容=1%で算出
テスト1考察
日本株が苦手そう
CAD、UKX、4452、5711、7201
上下に振れやすく長いトレンドが少ない → パッとせず
5-ATR ✕ 3 以上の値動きが少ない
テスト2
table:テスト2設定
s m l Pyramiding
1 150 350 5-ATR150 上限4
テスト1で成績の悪かった銘柄に対して、最適化(損失が小さくなるように)してみた
table:テスト2結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 90.64 21.22 113 32 28.32 4.965 162 18
EURJPY 156.50 24.32 138 29 21.01 7.924 174 13
GBPJPY 354.31 39.93 126 32 25.4 8.499 173 14
CHFJPY 18.79 45.72 154 26 16.88 5.572 149 14
CADJPY -77.29 97.44 176 32 18.18 2.815 104 13
NKY 33574.65 7559.63 127 44 34.65 4.019 107 21
DJI 1324.22 16985.85 130 28 21.54 3.806 141 20
DAX -5342.57 13023.81 106 32 30.19 1.730 114 30
UKX -8076.90 9921.10 130 24 18.46 1.735 106 23
HSI 28281.58 45324.48 150 36 24.00 1.959 91 23
6098 4118.50 50.00 7 5 71.43 33.348 258 22
4452 -2840.00 4620.00 152 45 20.61 1.757 73 19
5711 2345.00 7905.00 143 39 27.27 2.978 87 21
7201 -695.20 1261.20 140 42 30.00 1.813 69 24
9984 82.89.00 7098.00 127 39 30.71 3.283 100 23
AAPL 385.75 67.70 90 38 42.22 5.470 202 23
AXP 92.25 46.47 131 40 30.53 3.547 116 16
BA 632.13 278.84 145 35 24.14 8.879 145 16
JNJ -99.03 121.42 123 24 19.51 1.659 100 25
MCD 161.95 50.08 131 36 27.48 5.769 133 15
GOLD 220330.00 51800.00 116 38 32.76 4.697 136 19
PLATINUM 105100.00 109340.00 142 33 23.24 5.211 142 15
WTI -9010.00 134710.00 127 27 21.26 3.587 119 23
CORN 19912.50 37237.50 173 28 16.18 6.247 118 15
SOY BEANS -3925.00 122412.50 120 21 17.50 4.618 144 33
TOTAL 3217 805 25.02 4.190
破産の確率 0.00
期待値/リスク 0.299
収益の見込み 961.111
※ 破産の確率は損失の許容=1%で算出
テスト2考察
リスクリワードの数値が高いものは、買い保有が長いものが多そう
最適化したからといって良くなるとは限らないことがわかる
テスト3
table:テスト3設定
s m l Pyramiding
1 300 600 5-ATR20 上限4
table:テスト3結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 82.00 34.27 84 18 21.43 6.872 315 33
EURJPY 73.74 28.29 108 29 26.85 4.160 203 27
GBPJPY 518.90 21.40 59 19 32.30 15.862 487 18
CHFJPY 8.05 81.01 114 21 18.42 4.673 232 21
CADJPY -9.06 50.13 122 24 19.67 3.815 209 21
NKY 17307.12 10219.66 101 31 30.69 3.700 184 24
DJI 22109.52 9373.40 91 18 19.78 9.044 337 25
DAX 13475.02 7250.57 81 26 32.10 4.462 274 28
UKX -2597.80 5676.00 83 21 25.3 2.107 187 30
HSI 14027.94 36333.24 91 26 28.57 3.218 202 36
6098 1774.50 0 4 4 100.00 - 307 -
4452 -714.00 7321.00 99 28 28.28 2.266 108 36
5711 -3025.00 11115.00 112 28 25.00 2.416 143 34
7201 -3734.60 3895.60 124 20 16.13 0.726 84 31
9984 9243.00 9164.00 76 21 27.63 4.269 241 36
AAPL 492.97 40.17 61 23 37.70 0.419 405 24
AXP 74.03 27.88 74 21 28.38 4.272 216 37
BA 823.14 77.65 87 27 31.03 11.726 270 25
JNJ -92.96 116.90 108 20 18.52 1.559 97 36
MCD 145.63 49.25 112 35 31.25 5.252 174 20
GOLD 279330.00 60690.00 59 17 28.81 7.923 413 42
PLATINUM 86340.00 77565.00 82 23 28.05 4.157 262 27
WTI 108730.00 164880.00 124 22 17.74 6.601 246 19
CORN 18000.00 25250.00 110 23 20.91 4.818 189 27
SOY BEANS 52450.00 31975.00 114 22 19.3 5.016 217 19
TOTAL 2280 567 24.87 4.797
破産の確率 0.00
期待値/リスク 0.442
収益の見込み 1006.732
※ 破産の確率は損失の許容=2%で算出
テスト3考察
ATR算出期間の違いによる成績の差は殆どない。どちらでも。
テスト4
table:テスト4設定
s m l Pyramiding
1 300 600 2-ATR300 上限4
table:テスト4結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 128.46 48.70 106 28 26.48 6.266 289 29
EURJPY 129.50 45.31 134 38 28.36 4.307 216 22
GBPJPY 606.87 26.20 68 20 29.41 15.881 506 21
CHFJPY 2.39 101.01 148 30 20.27 3.983 222 23
CADJPY -14.32 76.99 154 30 19.48 3.839 207 24
NKY 17449.87 16852.65 130 34 26.15 3.960 201 25
DJI 22668.14 13775.29 124 24 19.35 7.061 332 22
UKX 19106.37 7390.08 96 32 33.33 4.541 288 20
DAX 7002.20 10878.70 118 26 22.03 2.054 211 31
HSI 16490.10 37757.39 112 20 25.89 3.685 216 42
6098 2649.50 0 4 4 100.00 - 354 -
4452 -4222.00 12604.00 133 34 25.56 2.034 126 35
5711 -4955.00 13305.00 143 36 25.17 2.323 157 34
7201 -5412.30 5702.30 159 26 16.35 0.777 108 32
9984 10337.00 11647.00 91 22 24.18 4.819 270 35
AAPL 483.36 109.91 82 24 29.27 7.738 426 30
AXP 138.65 38.69 98 32 32.65 4.327 219 36
BA 835.09 127.72 112 32 28.57 9.066 270 29
JNJ -94.50 165.96 135 27 20.00 1.946 118 39
MCD 184.67 98.18 136 40 29.41 5.092 190 20
GOLD 276020.00 90300.00 82 21 25.61 6.714 407 46
PLATINUM 91595.00 135900.00 106 25 23.58 4.661 295 32
WTI 171350.00 190920.00 147 20 19.73 6.320 247 19
CORN 13275.00 40200.00 144 30 20.83 4.285 201 27
SOY BEANS 13812.50 83800.00 146 24 16.44 5.324 238 23
TOTAL
破産の確率
期待値/リスク
収益の見込み
※ 破産の確率は損失の許容=2%で算出
テスト4考察
ATR算出期間の違いによる成績の差は殆どない。どちらでも。
テスト5
table:テスト5設定
s m l Pyramiding
1 300 600 None
table:テスト5結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 40.10 13.55 65 12 18.46 8.792 217 11
EURJPY 44.28 15.05 82 18 21.95 5.830 147 7
GBPJPY 149.62 19.04 43 7 16.28 19.259 397 10
CHFJPY 5.83 25.65 93 16 17.20 5.27 146 10
CADJPY 5.89 22.41 95 14 14.74 6.316 160 10
NKY 3500.61 6007.31 78 19 24.36 3.751 106 16
DJI 2976.40 6834.99 73 8 10.96 9.903 290 15
DAX 4944.73 3313.48 61 14 22.95 5.868 185 11
UKX -2827.50 4091.10 67 13 19.40 2.330 146 24
HSI 5271.37 11618.53 67 17 25.37 3.667 136 17
6098 764.50 0 1 1 100.00 - 391 -
4452 -2821.00 5368.00 85 23 27.06 1.519 66 25
5711 1005.00 2380.00 81 19 23.46 3.556 109 13
7201 -2071.70 2119.70 102 17 16.67 0.866 64 19
9984 2577.00 2817.00 56 10 17.86 6.431 173 24
AAPL 130.78 32.35 39 8 20.51 11.748 358 15
AXP 40.39 19.34 56 15 26.79 4.842 162 9
BA 238.41 39.50 62 14 22.58 12.214 197 10
JNJ -57.06 83.78 94 18 19.15 1.729 81 21
MCD 45.55 35.03 93 23 24.73 4.992 99 10
GOLD 100790.00 21200.00 42 9 21.43 9.774 294 18
PLATINUM 53525.00 23765.00 57 12 21.05 7.981 221 9
WTI 17460.00 70180.00 103 12 11.65 8.481 188 9
CORN 300.00 14462.50 90 13 14.44 5.965 151 14
SOY BEANS -6825.00 27125.00 95 13 13.68 5.696 148 13
TOTAL 1780 345 19.38 5.639
破産の確率 0.01
期待値/リスク 0.287
収益の見込み 510.459
※ 破産の確率は損失の許容=1%で算出
テスト5考察
テスト6
table:テスト6設定
s m l Pyramiding
1 150 350 None
table:テスト6結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 45.16 10.88 86 18 20.93 7.103 143 8
EURJPY 47.46 25.05 113 15 13.27 0.668 148 8
GBPJPY 137.84 15.42 98 19 19.39 10.205 128 7
CHFJPY 20.10 36.60 132 17 12.88 5.432 112 10
CADJPY 49.35 75.77 149 23 15.44 3.397 86 8
NKY 13670.52 3182.57 94 28 20.79 4.610 71 13
DJI -6.90 7479.40 95 17 17.89 4.586 122 13
DAX 2112.72 5172.27 76 22 28.95 2.011 88 23
UKX 4288.20 5943.00 106 19 17.92 2.266 93 15
HSI -8070.62 18323.04 112 24 21.43 2.909 80 12
6098 1225.50 50.00 4 2 50.00 25.51 207 22
4452 -1750.00 3245.00 126 33 26.19 2.064 51 13
5711 1250.00 2940.00 111 30 27.03 3.018 66 11
7201 -486.30 734.30 116 35 30.17 1.707 52 15
9984 2559.00 4554.00 96 27 28.13 3.327 76 12
AAPL 115.00 40.07 55 16 29.09 5.841 174 8
AXP 38.36 23.20 103 28 27.18 3.825 81 8
BA 102.35 170.44 120 22 18.33 6.507 87 12
JNJ -73.37 89.82 105 19 18.10 1.829 79 18
MCD 38.34 42.63 105 21 20.00 5.546 100 11
GOLD 98060.00 31530.00 89 24 26.97 5.509 100 10
PLATINUM 55120.00 32760.00 114 21 18.42 7.391 102 8
WTI -24070.00 81010.00 104 18 17.31 4.173 101 16
CORN -11562.50 25425.00 147 16 10.88 6.659 95 10
SOY BEANS -20712.50 53837.50 100 16 16.00 4.104 88 20
TOTAL 2556 530 20.74 4.255
破産の確率 1.76
期待値/リスク 0.090
収益の見込み 229.320
※ 破産の確率は損失の許容=1%で算出
テスト6考察
テスト5と6の比較
DJI
細切れになったのがよくなさそう
長期(テスト5)は売りのチャレンジが少なくて済んでいる
テスト5(300、600)利益
https://gyazo.com/8df625b890c719f95f6d150536952d1d
テスト6(150、350)損失
https://gyazo.com/75e45154486d5bb9ba499ed8ae2f6211
HSI
トレンド終盤の急激な戻しへの対応の差(利益確定が早くなる)
テスト5(300、600) 損失
https://gyazo.com/6248466491e66a857d0a203bf2832595
テスト6(150、350) 利益
https://gyazo.com/d772a68ec093a6882d2c2f1686b79a14
WTI
細切れ、不要なチャレンジが増えている
テスト5(150、350)利益
https://gyazo.com/1d2494bc53c4154ca523b0ecd04e4787
テスト6(300、600)損失
https://gyazo.com/e704ef950405c3c08e0c70cc29ee2752
テスト7
table:テス7設定
s m l Pyramiding
1 300 600 5-ATR300 上限4
※ mの傾きを追加
※ シグナルの判断を厳密に
crossover、crossunder
table:テスト7結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 84.09 30.18 87 19 21.84 6.669 318 30
EURJPY 62.44 40.20 108 28 25.93 4.082 198 27
GBPJPY 516.08 21.18 58 19 32.76 15.821 478 16
CHFJPY 20.54 74.27 113 23 20.35 4.506 218 22
CADJPY -45.00 86.58 123 23 18.70 3.191 207 23
NKY 19673.91 8967.63 100 30 30.00 4.101 186 25
DJI 23502.04 8969.65 95 22 23.16 7.362 308 20
DAX 555.01 5618.07 82 23 28.05 2.665 188 27
UKX -7593.40 7593.40 81 14 17.28 1.618 144 38
HSI -27592.16 44529.80 89 22 24.72 1.525 124 37
6098 4877.00 0 4 4 100.00 - 517 -
4452 -2590.00 8363.00 102 31 30.39 1.647 112 32
5711 -11495.00 12455.00 106 23 21.70 1.401 110 33
7201 -4096.60 4145.60 122 20 16.39 0.588 83 31
9984 10921.00 7341.00 75 21 28.00 4.760 224 37
AAPL 500.53 53.66 57 19 33.33 11.214 427 24
AXP 85.61 30.36 78 24 30.77 4.024 211 35
BA 704.63 114.79 88 24 27.27 10.263 242 28
JNJ -91.84 118.55 108 22 20.37 1.453 96 32
MCD 155.38 47.85 113 36 31.86 5.225 169 20
GOLD 77100.00 73310.00 56 12 21.43 5.25 312 63
PLATINUM 26975.00 96195.00 79 20 25.32 3.452 237 25
WTI 54280.00 165880.00 121 18 14.88 6.941 224 19
CORN 4137.50 28437.50 113 24 21.24 3.901 182 28
SOY BEANS 39212.50 53887.50 114 21 18.42 5.667 222 23
TOTAL 2272 542 23.86 4.726
破産の確率 0.00
期待値/リスク 0.366
収益の見込み 831.757
※ 破産の確率は損失の許容=1%で算出
テスト6考察
Pineスクリプト
code:Pineスクリプト(js)
//@version=3
strategy("Strategy Long Double EMA and Close"
,default_qty_type=strategy.fixed
,default_qty_value=1
,pyramiding=4
,overlay=true)
src = close
S = input(1 ,minval=1 ,title="short_")
M = input(300 ,minval=1 ,title="middle_") // 900/6/25 = 6ヶ月
L = input(600 ,minval=1 ,title="long_") // 1800/6/25 = 12ヶ月
SO_bool = input(false,type=bool ,title="loss cut")
SO_len = input(20 ,type=integer ,minval=1 ,title="loss cut ATR length")
SO_N = input(2 ,type=float ,minval=0.5 ,title="loss cut ATR*N")
MAX_N = input(4 ,type=integer ,minval=1 ,maxval=4 ,title="maximun num of unit")
LO_len = input(300 ,type=integer ,minval=1 ,title="pyramiding ATR length")
LO_N = input(5 ,type=float ,minval=0.5 ,title="pyramiding ATR*N")
Tm_bool = input(false,type=bool ,title="timed exit")
Tm_len = input(80 ,type=integer ,minval=1 ,title="timed exit length")
fromYear = input(2005 ,type=integer ,minval=1900 ,title="test start")
endYear = input(2017 ,type=integer ,minval=1900 ,title="test end")
isWork = timestamp(fromYear ,1 ,1 ,00 ,00) <= time and time < timestamp(endYear+1 ,1 ,1 ,00 ,00)
S_ = ema(close ,S)
M_ = ema(close ,M)
L_ = ema(close ,L)
atr_SO_ = ema(tr ,SO_len)
atr_LO_ = ema(tr ,LO_len)
atr_SO = atr_SO_*SO_N
atr_LO = atr_LO_*LO_N
Stage = 0
Stage := S_==M_ or M_==L_ or S_==L_ ? nz(Stage1) : S_ > M_ and M_ > L_ ? 1
: M_ > S_ and S_ > L_ ? 2
: M_ > L_ and L_ > S_ ? 3
: L_ > M_ and M_ > S_ ? 4
: L_ > S_ and S_ > M_ ? 5
: S_ > L_ and L_ > M_ ? 6
: na
countTradingDays = na
countNonTradingDays = na
countTradingDays := strategy.position_size==0 ? 0 : countTradingDays1 + 1 countNonTradingDays := strategy.position_size!=0 ? 0 : countNonTradingDays1 + 1 entry1 = close
entry2 = close
entry3 = close
entry4 = close
entry1 := strategy.position_size==0 ? na : entry11 entry2 := strategy.position_size==0 ? na : entry21 entry3 := strategy.position_size==0 ? na : entry31 entry4 := strategy.position_size==0 ? na : entry41 lo2 = close
lo3 = close
lo4 = close
lo2 := strategy.position_size==0 ? na : lo21 lo3 := strategy.position_size==0 ? na : lo31 lo4 := strategy.position_size==0 ? na : lo41 L_EntrySig = (Stage==6 or Stage==1) and strategy.position_size==0
S_EntrySig = (Stage==3 or Stage==4) and strategy.position_size==0
lo_sig2 = strategy.position_size>0 ? lo2 < high : strategy.position_size<0 ? lo2 > low : na
lo_sig3 = strategy.position_size>0 ? lo3 < high : strategy.position_size<0 ? lo3 > low : na
lo_sig4 = strategy.position_size>0 ? lo4 < high : strategy.position_size<0 ? lo4 > low : na
losscut = close
losscut := SO_bool==false ? na
: L_EntrySig ? close - atr_SO
: S_EntrySig ? close + atr_SO
: strategy.position_size>0 and (lo_sig2 or lo_sig3 or lo_sig4) ? close - atr_SO
: strategy.position_size<0 and (lo_sig2 or lo_sig3 or lo_sig4) ? close + atr_SO
: strategy.position_size!=0 ? losscut1 : na
ExitPrice = close
ExitPrice := L_EntrySig or strategy.position_size>0 ? SO_bool ? losscut : na
: S_EntrySig or strategy.position_size<0 ? SO_bool ? losscut : na
: na
if(strategy.position_size != 0)
L_ExitSig = (Stage==2 or Stage==5 or S_EntrySig) and strategy.position_size > 0
S_ExitSig = (Stage==5 or Stage==2 or L_EntrySig) and strategy.position_size < 0
TimedSig = countTradingDays > Tm_len and Tm_bool
strategy.close_all(when = L_ExitSig or S_ExitSig or TimedSig)
if(L_ExitSig or S_ExitSig)
entry1 := na
entry2 := na
entry3 := na
entry4 := na
lo2 := na
lo3 := na
lo4 := na
losscut := na
if(strategy.position_size > 0)
strategy.exit("L-Entry1" ,stop=ExitPrice)
if(entry2!=na)
strategy.exit("L-Entry2" ,stop=ExitPrice)
if(entry3!=na)
strategy.exit("L-Entry3" ,stop=ExitPrice)
if(entry4!=na)
strategy.exit("L-Entry4" ,stop=ExitPrice)
if(lo_sig2 and MAX_N >= 2)
lo2 := na
if(SO_bool)
strategy.entry("L-Entry2" ,strategy.long ,stop=ExitPrice ,comment="L-Entry2")
strategy.exit("L-Entry1" ,stop=ExitPrice)
else
strategy.entry("L-Entry2" ,strategy.long ,comment="L-Entry2")
if(lo_sig3 and MAX_N >= 3)
lo3 := na
if(SO_bool)
strategy.entry("L-Entry3" ,strategy.long ,stop=ExitPrice ,comment="L-Entry3")
strategy.exit("L-Entry2" ,stop=ExitPrice)
strategy.exit("L-Entry1" ,stop=ExitPrice)
else
strategy.entry("L-Entry3" ,strategy.long ,comment="L-Entry3")
if(lo_sig4 and MAX_N >= 4)
lo4 := na
if(SO_bool)
strategy.entry("L-Entry4" ,strategy.long ,stop=ExitPrice ,comment="L-Entry4")
strategy.exit("L-Entry3" ,stop=ExitPrice)
strategy.exit("L-Entry2" ,stop=ExitPrice)
strategy.exit("L-Entry1" ,stop=ExitPrice)
else
strategy.entry("L-Entry4" ,strategy.long ,comment="L-Entry4")
if(strategy.position_size < 0)
strategy.exit("S-Entry1" ,stop=ExitPrice)
if(entry2!=na)
strategy.exit("S-Entry2" ,stop=ExitPrice)
if(entry3!=na)
strategy.exit("S-Entry3" ,stop=ExitPrice)
if(entry4!=na)
strategy.exit("S-Entry4" ,stop=ExitPrice)
if(lo_sig2 and MAX_N >= 2)
lo2 := na
if(SO_bool)
strategy.entry("S-Entry2" ,strategy.short ,stop=ExitPrice ,comment="S-Entry2")
strategy.exit("S-Entry1" ,stop=ExitPrice)
else
strategy.entry("S-Entry2" ,strategy.short ,comment="S-Entry2")
if(lo_sig3 and MAX_N >= 3)
lo3 := na
if(SO_bool)
strategy.entry("S-Entry3" ,strategy.short ,stop=ExitPrice ,comment="S-Entry3")
strategy.exit("S-Entry2" ,stop=ExitPrice)
strategy.exit("S-Entry1" ,stop=ExitPrice)
else
strategy.entry("S-Entry3" ,strategy.short ,comment="S-Entry3")
if(lo_sig4 and MAX_N >= 4)
lo4 := na
if(SO_bool)
strategy.entry("S-Entry4" ,strategy.short ,stop=ExitPrice ,comment="S-Entry4")
strategy.exit("S-Entry3" ,stop=ExitPrice)
strategy.exit("S-Entry2" ,stop=ExitPrice)
strategy.exit("S-Entry1" ,stop=ExitPrice)
else
strategy.entry("S-Entry4" ,strategy.short ,comment="S-Entry4")
if((L_EntrySig or S_EntrySig) and isWork and strategy.position_size==0)
countTradingDays := 0
entry1 := close
if(L_EntrySig)
if(SO_bool)
strategy.entry("L-Entry1" ,strategy.long ,stop=ExitPrice ,comment="L-Entry1")
else
strategy.entry("L-Entry1" ,strategy.long ,comment="L-Entry1")
lo2 := MAX_N >= 2 ? close + atr_LO : na
lo3 := MAX_N >= 3 ? close + atr_LO * 2 : na
lo4 := MAX_N >= 4 ? close + atr_LO * 3 : na
if(S_EntrySig)
if(SO_bool)
strategy.entry("S-Entry1" ,strategy.short ,stop=ExitPrice ,comment="S-Entry1")
else
strategy.entry("S-Entry1" ,strategy.short ,comment="S-Entry1")
lo2 := MAX_N >= 2 ? close - atr_LO : na
lo3 := MAX_N >= 3 ? close - atr_LO * 2 : na
lo4 := MAX_N >= 4 ? close - atr_LO * 3 : na
plot(strategy.position_size ,transp=0 ,title="保有ポジションの数")
plot(strategy.openprofit ,transp=0 ,title="未決済の損益")
plot(strategy.netprofit ,transp=0 ,title="決済済みの損益")
plot(strategy.closedtrades ,transp=0 ,title="決済済み取引数")
plot(countTradingDays ,transp=0 ,title="取引日数")
plot(countNonTradingDays ,transp=0 ,title="ノンポジ日数")
plot(entry1 ,title="entry1" ,color=blue ,transp=0 ,style=linebr)
plot(lo2 ,title="lo2" ,color=red ,transp=0 ,style=linebr)
plot(lo3 ,title="lo3" ,color=red ,transp=0 ,style=linebr)
plot(lo4 ,title="lo4" ,color=red ,transp=0 ,style=linebr)
plot(losscut ,title="losscut" ,color=red ,transp=0 ,style=linebr)
plot(ExitPrice ,title="ExitPrice" ,color=red ,transp=0 ,style=linebr)
plot(atr_SO ,transp=0 ,title="ATR_SO")
plot(atr_LO ,transp=0 ,title="ATR_LO")
// plot(strategy.max_drawdown ,transp=50 ,title="最大DD")
// plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)
p1 = plot(L_ ,color=#303F9F ,title="長期EMA" ,style=line ,linewidth=2, transp=0)
p2 = plot(M_ ,color=#4CAF50 ,title="中期EMA" ,style=line ,linewidth=2, transp=0)
plot(S_ ,color=red ,title="短期EMA" ,style=line ,linewidth=2 ,transp=0)